//
//  MBaseViewController.m
//  zwyb
//
//  Created by 阔 李 on 16/11/3.
//  Copyright © 2016年 yxnzb. All rights reserved.
//

#import "MBaseViewController.h"

// 判断是否为iOS7
#define iOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)

@interface MBaseViewController ()<UIGestureRecognizerDelegate>

@end

@implementation MBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //  不让顶部nav占位 不透明处理
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
    
    // iOS7顶部屏幕适配
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]){
        
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
#endif
    
    self.view.backgroundColor=[UIColor whiteColor];
    
    [self initNavLeftBtn];
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
   //  获取系统自带滑动手势的target对象
//    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
//
//   //  创建全屏滑动手势，调用系统自带滑动手势的target的action方法
//    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
//
//    // 设置手势代理，拦截手势触发
//    pan.delegate = self;
//
//    // 给导航控制器的view添加全屏滑动手势
//    [self.view addGestureRecognizer:pan];
//
//
//
//    // 禁止使用系统自带的滑动手势
//    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

////设置顶部20的部分字体颜色变为白色
//- (UIStatusBarStyle)preferredStatusBarStyle{
//
//    return UIStatusBarStyleLightContent;
//
//}

#pragma mark 初始化nav left
-(void)initNavLeftBtn{
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *img = [UIImage imageNamed:@"common_back_btn"];
    
    leftBtn.frame = CGRectMake(0, 0, img.size.width, img.size.height);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"common_back_btn"] forState:UIControlStateNormal];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"common_back_btn"] forState:UIControlStateSelected];
    [leftBtn addTarget:self action:@selector(leftNavItemClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarBtn = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarBtn;
}

-(void)leftNavItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 隐藏navleft
- (void)leftNavHide{
    
    self.navigationItem.leftBarButtonItem.customView.hidden = YES;
}

#pragma mark 隐藏navright
- (void)rightNavHide{
    
    self.navigationItem.rightBarButtonItem.customView.hidden=YES;
}
#pragma mark 复写title
-(void)setTitle:(NSString *)title{
    
    [super setTitle:title];
    
    UILabel *titlelabel = [[UILabel alloc]initWithFrame:CGRectZero];
    titlelabel.backgroundColor = [UIColor clearColor];
    titlelabel.text = title;
  //  titlelabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:(18)];
    titlelabel.font = [UIFont fontWithName:@"DINEngschrift LT Alternate" size:16];
    
    titlelabel.textColor = getColor(@"333333");
    
    [titlelabel sizeToFit];
    self.navigationItem.titleView = titlelabel;
    
}

- (void)headerOneView{
    
    UIView *viewOf = [[UIView alloc] init];
    viewOf.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, 10);
    [self.view addSubview:viewOf];
    viewOf.backgroundColor = getColor(@"F5F5F5");
    
    //渐变
    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, 10);
    gradient.colors = [NSArray arrayWithObjects:
                       (id)getColor(@"E7E7E7").CGColor,
                       (id)getColor(@"FBFBFB").CGColor,nil];
    [viewOf.layer addSublayer:gradient];

    
    
    
}
@end
